﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ApiCoreProject.Bll.Interface;
using Microsoft.AspNetCore.Authorization;
using System.Dynamic;

namespace ApiCoreProject.Api.Controllers
{
    [Authorize]
    [Route("api/[controller]")]
    [ApiController]
    public class AuthorityController : ControllerBase
    {
        private readonly IAuthorityServe authorityServe;

        public AuthorityController(IAuthorityServe authorityServe)
        {
            this.authorityServe = authorityServe;
        }

        [HttpGet]
        public dynamic getMenus() {
            try
            {
                var role = HttpContext.User.Claims.ToList()[0].Value;
                int roleID = int.Parse(role);
                //var isrole = HttpContext.User.IsInRole("User");
                return authorityServe.GetAuthorityMenusByRoleID(roleID);
            }
            catch (Exception)
            {
                dynamic d = new ExpandoObject();
                d.code = -1;
                d.msg = "身份验证异常！";
                return d;
                throw;
            }
        }
    }
}
